/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller;

import java.util.List;
import queenb.net.entitybean.N000;
import queenb.web.store.N000Store;
import queenb.web.util.Util;

/**
 *
 * @author Nguyen Hung
 */
public class N000Controller extends QueenbController {

    private int pn000;
    private String nv001;
    private String nv002;
    private String nv003;
    private String nv004;
    private N000Store n000Store;

    public N000Controller() {
        n000Store = new N000Store();
        Object n000Object = getRequest().getParameter("pn000");
        if(n000Object != null)
        {
            this.pn000 = Util.parseInt(n000Object);
            getDetailEditN450(pn000);
        }
    }

    public void updateN000() {
        try {
            int row = n000Store.updateN000(pn000, getLogin().getModule(), getLogin().getCompanyNo(),nv001, nv002, nv003, nv004, getLogin().getUserName());
            if (row > 0) {
                showGlobalReport(true, getResourceString("datasavesuccessful"));
            } else {

                showGlobalReport(true, getResourceString("datasuccessfail"));
            }
            sendRedirectUrlTab("setting.jsp?tab=header12&linkN1000"+Util.convertMD5(getRequest().getRequestURI()));
        } catch (Exception e) {
            System.out.print(e.getMessage());
        }
    }

    public List<N000> getListAllN000() {

        try {

            List<N000> list = n000Store.getListN000(getLogin().getModule(), getLogin().getCompanyNo(), getLogin().getUserName());
            return list;
        } catch (Exception ex) {
            System.out.println(ex);
            return null;
        }

    }
    
    public void getDetailEditN450(int id) {
        try {
            List<N000> listN850Edit = getListAllN000();
            if (listN850Edit.size() > 0) {
                for (int i = 0; i < listN850Edit.size(); i++) {
                    if (listN850Edit.get(i).getPn000() == id) {
                        System.out.println("------------->>" + listN850Edit.get(i).getNv001());
                        this.nv001 = listN850Edit.get(i).getNv001();
                        this.nv003 = listN850Edit.get(i).getNv003();
                        break;
                    }
                }
            }
        } catch (Exception ex) {
            System.out.println("Error when getDetailEditN850. ERROR CODE: " + ex.getMessage());
        }
    }

    /**
     * @return the pn000
     */
    public int getPn000() {
        return pn000;
    }

    /**
     * @param pn000 the pn000 to set
     */
    public void setPn000(int pn000) {
        this.pn000 = pn000;
    }

    /**
     * @return the nv002
     */
    public String getNv002() {
        return nv002;
    }

    /**
     * @param nv002 the nv002 to set
     */
    public void setNv002(String nv002) {
        this.nv002 = nv002;
    }

    /**
     * @return the nv003
     */
    public String getNv003() {
        return nv003;
    }

    /**
     * @param nv003 the nv003 to set
     */
    public void setNv003(String nv003) {
        this.nv003 = nv003;
    }

    /**
     * @return the nv004
     */
    public String getNv004() {
        return nv004;
    }

    /**
     * @param nv004 the nv004 to set
     */
    public void setNv004(String nv004) {
        this.nv004 = nv004;
    }

    /**
     * @return the nv001
     */
    public String getNv001() {
        return nv001;
    }

    /**
     * @param nv001 the nv001 to set
     */
    public void setNv001(String nv001) {
        this.nv001 = nv001;
    }
}
